package com.hz.ys_taskinfo.action;


import java.util.ArrayList;
import java.util.List;

import com.hz.framework.MyAction.BaseAction;
import com.hz.framework.dao.CommonDao;
import com.hz.framework.util.CommonUtils;
import com.hz.framework.util.DateUtil;
import com.hz.framework.util.SqlParameter;
import com.hz.ys_clientorder.bean.Clientinfo;
import com.hz.ys_clientorder.bean.MuiltTaskinfo;
import com.hz.ys_clientorder.bean.Orderinfo;
import com.hz.ys_clientorder.bean.Taskinfo;
import com.hz.ys_clientorder.dao.OrderDao;
import com.hz.ys_stock.bean.PresMakings;
import com.hz.ys_system.dao.QueryDao;

/**
 * *****************************************************************************
 *               Copyright(c) 2010 by 哈尔滨华泽数码科技有限公司.
 *                       All rights reserved.
 *******************************************************************************
 *     File Name         :  com.hz.hzsearch.action.DynamicAction.java
 *     Description(说明)	: 动态查询检索 action
 * -----------------------------------------------------------------------------
 *     No.        Date              Revised by           Description	
 *     			  Jul 29, 2011           韩飞              Created
 *****************************************************************************
 */
public class TaskinfoAction extends BaseAction {

	CommonDao cd = new CommonDao();
	OrderDao dao = new OrderDao();
	private Taskinfo t ;
	
	public Taskinfo getT() {
		return t;
	}
	public void setT(Taskinfo t) {
		this.t = t;
	}
	/**
	 * 
	 * @author 吕滋源
	 * @time 2011-11-16	
	 * @return 
	 * 方法功能:模糊查询list
	 * 所属模块:任务单管理
	 */
	public String list(){

		String sql = "select t.id as tid,o.id as oid,y.gid as gid,t.taskid as taskid,t.taskname,o.name as ordername," +
					 "t.status as taskStatus,t.printSize,t.CTP,t.amount,mto.id as mtid,t.createtime " +
				"from taskinfo t " +
				"left join orderinfo o on t.orderid=o.orderid " +
				"left join pres_makings as y on t.goodsid = y.goodsid " +
				"left join machinetask as mto on t.taskid = mto.taskid " +
				"where o.status='已审核' ";
		
		sql += new QueryDao().QueryInfo(request , new SqlParameter("taskname","name") , "like");
		
		
		sql += "order by t.createtime desc";
		doAllSearchList(request, "list", sql , "jdbc");
		
//		List list = (List) request.getAttribute("list");
		return SUCCESS;
	}
	/**
	 * 
	 * @author 吕滋源
	 * @time 2011-11-16	
	 * @return 
	 * 方法功能:插入操作
	 * 所属模块:任务单管理
	 */
	public String ins(){
		
		return SUCCESS;
	}
	
	/**
	 * 
	 * @author 吕滋源
	 * @time 2011-11-16	
	 * @return 
	 * 方法功能:删除操作
	 * 所属模块:任务单管理
	 */
	public String del(){
		String oid=request.getParameter("oid");//任务单编号
		cd.DeleteHql("Orderinfo", "id", oid);
		return SUCCESS;
	}
	/**
	 * 
	 * @author 吕滋源
	 * @time 2011-11-16	
	 * @return 
	 * 方法功能:修改操作
	 * 所属模块:任务单管理
	 */
	public String upd(){
		cd.updateinfor(t);
		return SUCCESS;
	}
	/**
	 * 
	 * @author 吕滋源
	 * @time 2011-11-16	
	 * @return 
	 * 方法功能:查询单个任务单信息
	 * 所属模块:任务单管理
	 */
	public String sel(){
		String tid=request.getParameter("tid");//任务编号
		String oid=request.getParameter("oid");//订单编号
		Orderinfo order = (Orderinfo)cd.selHqlObj("FROM Orderinfo where id ='"+oid+"' or orderId='"+oid+"'");
		Taskinfo task = (Taskinfo)cd.selHqlObj("FROM Taskinfo where id ='"+tid+"' or taskid='"+tid+"'");
		Clientinfo client = (Clientinfo)cd.selHqlObj("FROM Clientinfo where clientId='"+order.getClientId()+"'");
		PresMakings p= (PresMakings)cd.selHqlObj("FROM PresMakings where goodsid ='"+task.getGoodsid()+"'");
		request.setAttribute("task", task);
		request.setAttribute("order", order);
		request.setAttribute("p", p);
		request.setAttribute("client", client);
		return SUCCESS;
	}
	/**
	 * 
	 * @author 吕滋源
	 * @time 2011-11-16	
	 * @return 
	 * 方法功能:查询单个任务单信息用于修改
	 * 所属模块:任务单管理
	 */
	public String selUpd(){
		String tid=request.getParameter("tid");//任务编号
		request.setAttribute("t",dao.sel(tid));
		return SUCCESS;
	}
}
